package com.fancy.middleware.common.initializing;

import com.fancy.middleware.common.utils.ContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ApplicationInitializing implements InitializingBean, ApplicationContextAware {
    private ApplicationContext ctx;

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("start init application .");
        ContextUtils.setApplicationContext(ctx);
        log.info("end init application .");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.ctx = applicationContext;
    }
}
